From: Ian Jackson Date: Mon, 3 Feb 2014 14:25:13 +0000 (+0000) Subject: libxl: events: timedereg internal unit test X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~5602 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=2920d6655a351e028591389a040a71039730788f;p=xen.git libxl: events: timedereg internal unit test Test timeout deregistration idempotency. In the current tree this test fails because ev->func is not cleared, meaning that a timeout can be removed from the list more than once, corrupting the list. It is necessary to use multiple timeouts to demonstrate this bug, because removing the very same entry twice from a list in quick succession, without modifying the list in other ways in between, doesn't actually corrupt the list. (Since removing an entry from a doubly-linked list just copies next and back from the disappearing entry into its neighbours.) Signed-off-by: Ian Jackson Cc: Jim Fehlig Cc: Ian Campbell Acked-by: Ian Campbell --- diff --git a/.gitignore b/.gitignore index 3504584c89..db3b0831cb 100644 --- a/.gitignore +++ b/.gitignore @@ -361,6 +361,7 @@ tools/libxl/testidl tools/libxl/testidl.c tools/libxl/*.pyc tools/libxl/libxl-save-helper +tools/libxl/test_timedereg tools/blktap2/control/tap-ctl tools/firmware/etherboot/eb-roms.h tools/firmware/etherboot/gpxe-git-snapshot.tar.gz diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile index cc21247fe7..66f3f3f7f1 100644 --- a/tools/libxl/Makefile +++ b/tools/libxl/Makefile @@ -79,7 +79,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y) LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o -LIBXL_TESTS += +LIBXL_TESTS += timedereg # Each entry FOO in LIBXL_TESTS has two main .c files: # libxl_test_FOO.c "inside libxl" code to support the test case # test_FOO.c "outside libxl" code to exercise the test case diff --git a/tools/libxl/libxl_test_timedereg.c b/tools/libxl/libxl_test_timedereg.c new file mode 100644 index 0000000000..a44639fece --- /dev/null +++ b/tools/libxl/libxl_test_timedereg.c @@ -0,0 +1,97 @@ +/* + * timedereg test case for the libxl event system + * + * To run this test: + * ./test_timedereg + * Success: + * program takes a few seconds, prints some debugging output and exits 0 + * Failure: + * crash + * + * set up [0]-group timeouts 0 1 2 + * wait for timeout 1 to occur + * deregister 0 and 2. 1 is supposed to be deregistered already + * register [1]-group 0 1 2 + * deregister 1 (should be a no-op) + * wait for [1]-group 0 1 2 in turn + * on final callback assert that all have been deregistered + */ + +#include "libxl_internal.h" + +#include "libxl_test_timedereg.h" + +#define NTIMES 3 +static const int ms[2][NTIMES] = { { 2000,1000,2000 }, { 1000,2000,3000 } }; +static libxl__ev_time et[2][NTIMES]; +static libxl__ao *tao; +static int seq; + +static void occurs(libxl__egc *egc, libxl__ev_time *ev, + const struct timeval *requested_abs); + +static void regs(libxl__gc *gc, int j) +{ + int rc, i; + LOG(DEBUG,"regs(%d)", j); + for (i=0; i + +int libxl_test_timedereg(libxl_ctx *ctx, libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; + +#endif /*TEST_TIMEDEREG_H*/ diff --git a/tools/libxl/test_timedereg.c b/tools/libxl/test_timedereg.c new file mode 100644 index 0000000000..0081ce3d2e --- /dev/null +++ b/tools/libxl/test_timedereg.c @@ -0,0 +1,11 @@ +#include "test_common.h" +#include "libxl_test_timedereg.h" + +int main(int argc, char **argv) { + int rc; + + test_common_setup(XTL_DEBUG); + + rc = libxl_test_timedereg(ctx, 0); + assert(!rc); +}